<template>
    <f7-app :params="f7params">
        <!-- Status bar overlay for fullscreen mode-->
        <!-- <f7-statusbar></f7-statusbar> -->
        <!-- Your main view, should have "view-main" class -->
        <f7-view main class="ios-edges" url="/"></f7-view>
    </f7-app>
</template>
<script>
import Vue from "vue";
import FrameworkInstall from "./libs/framework/install";
import Config from "./libs/config.js";
import _ from "lodash";
// import routes from "./routes";
import routes from "./routesCheck";
import provide from "./provide";

var stylesheet = document.createElement("style");
document.head.appendChild(stylesheet);
var globalTheme = "light";
var globalBarsStyle = "empty";
var globalCustomColor = "";
var globalCustomProperties = "";

export default {
    data () {
        return {
            // Framework7 Parameters
            f7params: {
                id: Config.info.id,
                name: Config.info.name, // App name
                theme: "md", // Automatic theme detection
                iosTranslucentBars: false,  // 半透明禁用
                iosTranslucentModals: false,
                // App root data
                data: function () {
                    return {
                        delayClickTime: 300,  // click事件延迟触发时间，单位毫秒
                        downloaders: []
                    };
                },
                dialog: {
                    title: "温馨提示",
                    buttonOk: "确定",
                    buttonCancel: "取消",
                    preloaderTitle: "加载中... ",
                    progressTitle: "加载中... "
                },
                searchbar: {
                    placeholder: "搜索",
                    disableButtonText: "取消"
                },
                smartSelect: {
                    pageBackLinkText: "返回",
                    popupCloseLinkText: "关闭",
                    sheetCloseLinkText: "确定",
                    searchbarPlaceholder: "搜索",
                    searchbarDisableText: "取消"
                },
                autocomplete: {
                    openIn: "popup",
                    limit: 50,
                    requestSourceOnOpen: true,
                    preloader: true,
                    pageBackLinkText: "返回",
                    popupCloseLinkText: "关闭",
                    searchbarPlaceholder: "输入关键字搜索",
                    searchbarDisableText: "取消",
                    notFoundText: "没有找到相关记录"
                },
                picker: {
                    toolbarCloseText: "确定"
                },
                photoBrowser: {
                    pageBackLinkText: "返回",
                    popupCloseLinkText: '关闭',
                    theme: "dark",
                    navbar: true,
                    toolbar: true,
                    navbarOfText: "/"
                },
                touch: {
                    disableContextMenu: false // 默认为false
                },
                view: {
                    animate: true,
                    pushState: true,
                    pushStateSeparator: '#',
                    // stackPages: true,
                    preloadPreviousPage: false, //预加载前一个页面
                    iosSwipeBack: false //iOS滑动返回
                },
                on: {
                    init () {
                        Vue.use(FrameworkInstall, this);
                        this.$(document).on('page:beforeout', event => {
                            vue.$framework.modules.isNeedRecord(event.detail.route.path, 'out')
                        });
                        this.$(document).on('page:beforein', event => {
                            //隐藏BM
                            let bjw = document.getElementById("baidu_jsapi_watermark");
                            if (bjw) {
                                bjw.style.display = "none";
                            }
                            vue.$framework.modules.isNeedRecord(event.detail.route.path, 'in')
                        });
                    },
                    error (m) {
                        this.preLoader.hide();
                        this.dialog.toast(m || "请求数据失败，请稍后重试");
                    },
                    pageInit: function (page) {
                        // 页面跳转清空vant待关闭的实例集合
                        // 为了解决手机物理返回不会关闭vant的popup等组件而会直接返回上一页的操作
                        Vue.prototype.vantToBeClosed = []
                    },
                    preroute: function (r) {
                        if (
                            _.indexOf(
                                [
                                    this.params.picker.url,
                                    this.params.smartSelect.url,
                                    this.params.autocomplete.url
                                ],
                                r.route.path
                            ) >= 0
                        ) {
                            return;
                        }
                        if (this.params.view.pushState && r.url && r.url.indexOf("/index.html") > -1) {
                            _.extend(r, this.router.findMatchingRoute(Config.pages.home));
                        }
                        console.log("preroute --> " + r.route.path);
                        if (r.route.anonymous != true && !(r.route.path=='/zjApp' || r.route.path=='/ajzApp') && !Vue.prototype.$framework.account.isLogin()) {
                            Vue.prototype.$framework.account.next({ ...r });
                            _.extend(r, this.router.findMatchingRoute(Config.pages.login));
                        }
                    },
                    preback: function (r) {
                        if ((!r.history || r.history.length <= 1) && window.qmsdk && window.plus) {
                            window.plus.webview.currentWebview().close();
                        }
                    }
                },
                // App routes
                routes: routes
            }
        };
    },
    methods: {},
    provide: provide,
    mounted () {
        this.$f7ready(f7 => { });
    }
};
</script>
